package WolfIsland;

import java.util.Random;
public abstract class Animal {
    protected String name;
    protected String nameR;
    protected int point;
    protected int birthday;
    
    abstract public void run(Animal[][] area, Animal[][] area2, int i, int j);
    
    public String getName(){
        return name;
    }
    
    public int getBirthday(){
        return birthday;
    }
    
    public void setBirthday(int day){
        this.birthday=day;
    }
    
    public String getNameR(){
        return nameR;
    }
    
    public int getPoint(){
        return point;
    }
    
    public void feed(){
        point+=10;
    }
    
    public void born(Animal[][] area, Animal[][] area2, int i, int j){
        int x=-1;
        int y=-1;
        int xx=-1;
        int yy=-1;
        Random rand = new Random();
        if(i-1>=0){x=i-1;}else{x=area.length-1;}; if(j-1>=0){y=j-1;}else{y=area[0].length-1;};
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;}
        if(i-1>=0){x=i-1;}else{x=area.length-1;}; y=j;
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;}
        if(i+1<area.length){x=i+1;}else{x=0;}; if(j-1>=0){y=j-1;}else{y=area[0].length-1;}
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;} 
        x=i; if(j-1>=0){y=j-1;}else{j=area[0].length-1;};
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;}
        x=i; if(j+1<area[0].length){y=j+1;}else{y=0;}; 
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;}
        if(i-1>=0){x=i-1;}else{x=area.length-1;}; if(j+1<area[0].length){y=j+1;}else{y=0;}; 
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;}
        if(i+1<area.length){x=i+1;}else{x=0;}; y=j; 
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;}
        if(i+1<area.length){x=i+1;}else{x=0;}; if(j+1<area[0].length){y=j+1;}else{y=0;};
        if(area[x][y].getName()=="Null" && area2[x][y].getName()=="Null"){xx=x;yy=y;}        
        if(!(xx==-1 & yy==-1)){switch((int)(rand.nextDouble()*2)){
        case 0: area2[xx][yy]=new Wolf(); area2[xx][yy].setBirthday(Main.day); break;
        case 1: area2[xx][yy]=new SWolf(); area2[xx][yy].setBirthday(Main.day); break;
        }}
    }
}
